/**
 * 
 */
package lastfmbaseball.core;

import java.util.*;

import lastfmbaseball.lastfm.*;

/**
 * @author DanBress
 * 
 */
public class AtBat
{
	private PlayerInGame pitcher;
	private PlayerInGame batter;
	private boolean isPinchHit;
	//private Umpire umpire;
	//private Song pitcherSong;
	//private Song batterSong;
	//private int pitcherRating;
	//private int batterRating;
	private RatedSong pitcherSong;
	private RatedSong batterSong;
	private List<BaseRunner> baseRunners;
	private AtBatResult result;

	public AtBat(PlayerInGame pitcher, PlayerInGame batter, RatedSong pitcherSong, RatedSong batterSong, List<BaseRunner> baseRunners,
			AtBatResult result, boolean isPinchHit)
	{
		this.pitcher = pitcher;
		this.batter = batter;
		this.pitcherSong = pitcherSong;
		this.batterSong = batterSong;
		this.baseRunners = baseRunners;
		this.result = result;
		this.isPinchHit = isPinchHit;
	}

	public List<BaseRunner> getBaseRunners()
	{
		return baseRunners;
	}

	public PlayerInGame getBatter()
	{
		return batter;
	}

	public int getOutsGenerated()
	{
		int outsGenerated = 0;
		for (int i = 0; i < baseRunners.size(); i++)
		{
			BaseRunner baseRunner = baseRunners.get(i);
			if (baseRunner.getState() == BaseRunnerState.Out)
			{
				++outsGenerated;
			}
		}

		return outsGenerated;
	}

	public int getRunsScored()
	{
		int runsScored = 0;
		for (int i = 0; i < baseRunners.size(); i++)
		{
			BaseRunner baseRunner = baseRunners.get(i);
			if (baseRunner.getBase() == Base.Home
					&& baseRunner.getState() == BaseRunnerState.Safe)
			{
				++runsScored;
			}
		}

		return runsScored;
	}

	@Override
	public String toString()
	{
		String returnValue = result + " " + getRunsScored() + " runs scored "
				+ getOutsGenerated() + " outs generated";

		return returnValue;
	}

}
